﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Drifting.MotionPlanning.Primitives
{
    public class Representation : State
    {
        State x_rep;
        HashSet<Representation> childrenSet;
        List<Representation> children;

        public Representation(double[] alias, State x_rep)
            : base(null, alias)
        {
            this.x_rep = x_rep;
            x_rep.Witness = this;
        }

        public State X
        {
            get { return x_rep; }
            set { x_rep = value; }
        }

        public List<Representation> Children
        {
            get
            {
                if(children == null)
                    children = new List<Representation>(512);
                return children;
            }
        }

        public void AddChild(Representation child)
        {
            if (childrenSet == null)
                childrenSet = new HashSet<Representation>();
            if (children == null)
                children = new List<Representation>(512);
            if (child != null)
                if (childrenSet.Contains(child) == false)
                {
                    childrenSet.Add(child);
                    children.Add(child);
                }
        }
    }
}
